import React from 'react';
import 'styles/data-center/report/travel-report/components/cost-center-item-select-for-report/cost-center-item-select-for-report.scss';
import CostCenterSearchForm from 'components/template/cost-center-search-form/cost-center-search-form'
import { messages } from "share/common";


class NewCostCenterSelector extends React.Component {
  state = {
    selectedData: []
  }

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    this.props.onRef({ key: "cost_center_item_code_from_to", value: this })
  }

  handleCancel = () => {
    const { onConfirm } = this.props;
    this.setState({
      selectedData: [],
    });
    onConfirm && onConfirm(undefined);
  };

  onConfirm = (value) => {
    const { onConfirm } = this.props;
    this.setState({
      selectedData: value
    });
    onConfirm && onConfirm(value);
  }

  render() {
    let { title, setOfBooksId } = this.props;
    const {
      selectedData
    } = this.state;
    return (
      <div>
        <div className='extra-sa-title'>
          {title}
        </div>
        <CostCenterSearchForm
          title={title}
          value={selectedData}
          onChange={this.onConfirm}
          setOfBooksId={setOfBooksId}
        />
      </div>
    );
  }

  static propTypes = {
    onConfirm: React.PropTypes.func.isRequired,// 点击确认之后的回调：返回结果
    title: React.PropTypes.any,//字段标题
    setOfBooksId: React.PropTypes.any,//账套id，需要有账套id查询成本中心
    onRef: React.PropTypes.func
  }

  static defaultProps = {
    title: messages('finance-7.key255')/*成本中心项*/,//由外面传入
    onConfirm: () => {
    },
    onRef: () => {
    },
  }
}

export default NewCostCenterSelector



